package com.driver.manage.ocr;

import com.driver.manage.utils.DateUtil;
import com.driver.manage.utils.GsonUtils;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

public class Format {
    public static HashMap<String, Object> idcard(String result) throws ParseException {
        Map map = GsonUtils.fromJson(result, Map.class);
        Map<String, Map<String, Object>> words_result = (Map<String, Map<String, Object>>) map.get("words_result");
        String name = (String) words_result.get("姓名").get("words");
        String gender = (String) words_result.get("性别").get("words");
        String nationality = (String) words_result.get("民族").get("words");
        String birthday = (String) words_result.get("出生").get("words");
        String date = DateUtil.date(birthday);
        String address = (String) words_result.get("住址").get("words");
        String idNumber = (String) words_result.get("公民身份号码").get("words");
        HashMap<String, Object> hashmap = new HashMap<>();
        hashmap.put("姓名" , name);
        hashmap.put("性别" , gender);
        hashmap.put("民族" , nationality);
        hashmap.put("出生日期" , date);
        hashmap.put("住址" , address);
        hashmap.put("身份证号码" , idNumber);
        return hashmap;
    }

    public static HashMap<String, Object> DrivingLicense(String result) throws ParseException {
        Map map = GsonUtils.fromJson(result, Map.class);
        Map<String,Map<String, Object>> words_result = (Map<String, Map<String, Object>>) map.get("words_result");
        String name = (String) words_result.get("姓名").get("words");
        String to = (String) words_result.get("至").get("words");
        String gender = (String) words_result.get("性别").get("words");
        String birthday = (String) words_result.get("出生日期").get("words");
        String date = DateUtil.date(birthday);
        String address = (String) words_result.get("住址").get("words");
        String idNumber = (String) words_result.get("证号").get("words");
        String unit = (String) words_result.get("发证单位").get("words");
        String firstDate = (String) words_result.get("初次领证日期").get("words");
        String date1 = DateUtil.date(firstDate);
        String nationality = (String) words_result.get("国籍").get("words");
        String driverType = (String) words_result.get("准驾车型").get("words");
        String validityPeriod = (String) words_result.get("有效期限").get("words");
        String date2 = DateUtil.date(validityPeriod);
        HashMap<String, Object> hashmap = new HashMap<>();
        hashmap.put("姓名" , name);
        hashmap.put("至" , to);
        hashmap.put("性别" , gender);
        hashmap.put("出生日期" , date);
        hashmap.put("住址" , address);
        hashmap.put("证号" , idNumber);
        hashmap.put("发证单位" , unit);
        hashmap.put("初次领证日期" , date1);
        hashmap.put("国籍" , nationality);
        hashmap.put("准驾车型" , driverType);
        hashmap.put("有效期限" , date2);
        return hashmap;
    }

    public static HashMap<String, Object> VehicleLicense(String result) throws ParseException {
        Map map = GsonUtils.fromJson(result, Map.class);
        Map<String,Map<String, Object>> words_result = (Map<String, Map<String, Object>>) map.get("words_result");
        String name = (String) words_result.get("姓名").get("words");
        String to = (String) words_result.get("至").get("words");
        String gender = (String) words_result.get("性别").get("words");
        String birthday = (String) words_result.get("出生日期").get("words");
        String date = DateUtil.date(birthday);
        String address = (String) words_result.get("住址").get("words");
        String idNumber = (String) words_result.get("证号").get("words");
        String unit = (String) words_result.get("发证单位").get("words");
        String firstDate = (String) words_result.get("初次领证日期").get("words");
        String date1 = DateUtil.date(firstDate);
        String nationality = (String) words_result.get("国籍").get("words");
        String driverType = (String) words_result.get("准驾车型").get("words");
        String validityPeriod = (String) words_result.get("有效期限").get("words");
        String date2 = DateUtil.date(validityPeriod);
        HashMap<String, Object> hashmap = new HashMap<>();
        hashmap.put("姓名" , name);
        hashmap.put("至" , to);
        hashmap.put("性别" , gender);
        hashmap.put("出生日期" , date);
        hashmap.put("住址" , address);
        hashmap.put("证号" , idNumber);
        hashmap.put("发证单位" , unit);
        hashmap.put("初次领证日期" , date1);
        hashmap.put("国籍" , nationality);
        hashmap.put("准驾车型" , driverType);
        hashmap.put("有效期限" , date2);
        return hashmap;
    }
}
